#include <stdlib.h>

int pack (int N, int status[N])
{
	int j, p;

	p = 0;
	for (j = 0; j < N; j++)
	{
		p = 2 * p + status[j];
	}

	return p;
}

void unpack (int p, int N, int status[N])
{
	int j;

	for (j = 0; j < N; j++)
	{
		status[N - 1 - j] = p % 2;
		p /= 2;
	}
}

/* calculate the next step for give state under the network using strong inhibition model */
int next_step (int N, int state[N], int j, int network[N])
{
	int k;

	for (k = 0; k < N; k++)
	{
		if (k == j)
			continue;
		if (state[k] == 1 && network[k] == -1)
			return 0;
	}

	for (k = 0; k < N; k++)
	{
		if (k == j)
			continue;
		if (state[k] == 1 && network[k] == 1)
			return 1;
	}

	if (network[j] == -1)
		return 0;
	else
		return state[j];
}
